<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="common/commonVant::commonStaticVant"></div>
    <script th:src="@{/common/localStorage.js}"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta charset="UTF-8">
    <title>我的收藏</title>
</head>
<body>
<div id="app" v-cloak>
    <van-swipe-cell v-for="(item,index) in collectionList" :key="index">
        <template #left>
            <van-button square type="primary" text="查看" @click="articleDetail(item.articleId)"/>
        </template>
        <van-cell-group>
            <van-cell :border="true" :title="item.articleTitle" :value="item.tabContent"/>
        </van-cell-group>
        <template #right>
            <van-button square type="danger" text="删除" @click="deleteCollections(item.articleId)"/>
        </template>
    </van-swipe-cell>
</div>
<script th:inline="javascript">
    let mvvm = new Vue({
        el: '#app',
        data: {
            token: '',
            collectionList: []
        },
        methods: {
            async getMyCollection() {
                const result = await httpPost("/collections/selectMyCollections", {}, {'Authorization': this.token});
                if (result.code == 200) {
                    this.collectionList = result.data;
                } else {

                }
            },
            async deleteCollections(articleId) {
                const result = await httpPost("/collections/deleteCollections", {articleId: articleId}, {'Authorization': this.token});
                if (result.code == 200) {
                    await this.getMyCollection();
                } else if (result.code == 206 || result.code == 205) {
                    window.location.href = window.location.origin + '/home/login';
                }
            },
            articleDetail(articleId) {
                window.location.href = [[${#request.getContextPath()}]] + '/home/articleDetail/' + articleId;
            }

        },
        mounted() {
            this.token = window.getLocalStorage("token");
            this.token = this.token ? this.token : '';
            if (!this.token) {
                window.location.href = '/home/login';
            }
            this.getMyCollection();
        }
    })
</script>
</body>
</html>